package com.sogoodsoft.web.account;

import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import com.sogoodsoft.entity.account.User;
import com.sogoodsoft.service.account.AccountManager;
import com.sogoodsoft.util.DwzMsg;
import com.sogoodsoft.util.InfosysSecurityUtil;
import com.sogoodsoft.web.CrudActionSupport;

/**
 * 修改密码和用自己修改资料
 * @author xiaozu
 *
 */
@SuppressWarnings("serial")
public class ProfileAction extends CrudActionSupport < User >  {

	 // -- 页面属性 --//
    private Long id;

    private User entity;

    private String passwordConfirm;



    @Autowired
    private AccountManager accountManager;


    
	@Override
	public String delete() throws Exception {
		return INPUT;
	}

	@Override
	public String input() throws Exception {
		return INPUT;
	}

	@Override
	public String list() throws Exception {
		return INPUT;
	}

	@Override
	protected void prepareModel() throws Exception {	
		entity = InfosysSecurityUtil.getCurrentUser();
		logger.debug("ProfileAction prepareModel");
	}

	@Override
	public String save() throws Exception {
		if(passwordConfirm.equals(entity.getPassword())){
		 accountManager.saveUser(entity);
		 Struts2Utils.renderJson(DwzMsg.successAndX());
		}else{
			 Struts2Utils.renderJson(DwzMsg.fail("两次密码输入不一致！"));
		}
		return null;
	}

	@Override
	public User getModel() {
		return entity;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public User getEntity() {
		return entity;
	}

	public void setEntity(User entity) {
		this.entity = entity;
	}

	public String getPasswordConfirm() {
		return passwordConfirm;
	}

	public void setPasswordConfirm(String passwordConfirm) {
		this.passwordConfirm = passwordConfirm;
	}


}
